We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392926 - -f obj SECTION ABSOLUTE= doesn't work as expected (like MASM SEGMENT AT)
Summary: -f obj SECTION ABSOLUTE= doesn't work as expected (like MASM SEGMENT AT)
Status: OPEN
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.16.xx
Hardware: All All
: Medium new functionality request
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2024-11-27 00:57 PST by E. C. Masloch
Modified: 2024-11-27 00:57 PST (History)
4 users (show)

Obtained from: Built from git using configure
Generated by: Human
Bug category:
Observed for: Development code
Regression: ---
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2024-11-27 00:57:52 PST
In my work of porting the MS-DOS v4 kernel to NASM I came across uses of eg "ROM SEGMENT AT 0F000h" [1]. 

In the manual, NASM's OMF -f obj output format is said [2] to have a SECTION ABSOLUTE= extension. Unfortunately, this doesn't do what I want it to do. It is described as follows: "The obj file format also allows segments to be declared as having a pre-defined absolute segment address, although no linkers are currently known to make sensible use of this feature; nevertheless, NASM allows you to declare a segment such as SEGMENT SCREEN ABSOLUTE=0xB800 if you need to. The ABSOLUTE and ALIGN keywords are mutually exclusive."

What I want is for "jmp far label" and "seg label" to be supported for absolute sections. To my understanding this support belongs into the assembler, as it knows the final segmented address of the absolute section.

Lacking this support I worked around it by explicitly specifying the absolute segment value to the jumps and I used the ABSOLUTE directive to place labels [3].

[1]: https://hg.pushbx.org/ecm/msdos4/file/28e097f848ba/src/BIOS/MSHARD.ASM#l59
[2]: https://www.nasm.us/xdoc/2.16.03/html/nasmdoc8.html#section-8.4.1
[3]: https://hg.pushbx.org/ecm/msdos4/rev/b35e275a8dae

Here are two test cases. The jmp gives an error and a panic. The SEG seems to be supported but does not relocate correctly: The assembler writes a zero and no relocation.

$ nasm -v
NASM version 2.16.02rc2 compiled on Oct 12 2023
$ cat test1.asm

        section CODE
jmp far abslabel

        section ABS absolute=0F000h
        resb 38
abslabel:
$ cat test2.asm

        section DATA
        dw foo, seg foo

        section ABS absolute=0F000h
        resb 42
foo:
$ nasm -f obj test1.asm -l /dev/stderr
     1
     2                                          section CODE
test1.asm:3: error: far-absolute relocations not supported by OBJ format
panic: test1.asm:3: unrecognised segment value in obj_write_fixup
$ nasm -f obj test2.asm -l /dev/stderr
     1
     2                                          section DATA
     3 00000000 [2A00]0000                      dw foo, seg foo
     4
     5                                          section ABS absolute=0F000h
     6 00000000 <res 2Ah>                       resb 42
     7                                  foo:
$